home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-10-28 | 2.2 KB | 86 lines | [TEXT/CWIE] |
- // StPPCBrowser © 1995 Nick Beadman
- // Implementation of class to prompt user for apple event target
-
- #include <LString.h>
- #include <UException.h>
- #include "StPPCBrowser.h"
-
- ConstSFTypeListPtr StPPCBrowser::sCreators;
- Int16 StPPCBrowser::sNofCreators;
- Boolean StPPCBrowser::sAllowLocal;
-
- StPPCBrowser::StPPCBrowser(Int16 inNofCreators, ConstSFTypeListPtr inCreators, TargetID& ioTarget, Boolean inDefaultTarget,
- Boolean inAllowLocal, ConstStr255Param inPrompt, ConstStr255Param inAppLabel)
- {
- // store the statics needed to do port filtering
- sCreators = inCreators;
- sNofCreators = inNofCreators;
- sAllowLocal = inAllowLocal;
-
- // assign the existing target ID to locals
- LocationNameRec lLocation;
- PortInfoRec lPortInfo;
- lLocation = ioTarget.location;
- lPortInfo.name = ioTarget.name;
-
- // make a port filter function;
- PPCFilterUPP lPortFilter = NewPPCFilterProc(PortFilter);
-
- {
- #ifdef Debug_Throw
- // It IS okay for the call to fail (user may cancel), so turn off Throw debugging.
- StValueChanger<EDebugAction>okayToFail(gDebugThrow, debugAction_Nothing);
- #endif
-
- OSErr lErr = ::PPCBrowser(inPrompt, inAppLabel, inDefaultTarget, &lLocation, &lPortInfo, lPortFilter, 0);
-
- // dispose of the port filter UPP
- DisposeRoutineDescriptor(lPortFilter);
-
- // assign the target to the location and port info
- ioTarget.location = lLocation;
- ioTarget.name = lPortInfo.name;
-
- ThrowIfOSErr_(lErr);
- }
- }
-
- StPPCBrowser::~StPPCBrowser()
- {
- }
-
- pascal Boolean StPPCBrowser::PortFilter(LocationNamePtr inLocation, PortInfoPtr inPortInfo)
- {
- Boolean lAllowInList = true;
-
- if (!(sAllowLocal) && (inLocation->locationKindSelector == ppcNoLocation))
- {
- lAllowInList = false;
- }
- else
- {
- // the first 4 chars of the port type string seems to be the creator !
- // this is undocumented %%%%
-
- // assume not in list if we have a list of creators
- if (sNofCreators != 0)
- {
- lAllowInList = false;
- }
-
- // get the port creator and compare with our creators
- LStr255 lPortCreator = inPortInfo->name.u.portTypeStr;
- for (Int16 i = 0; i < sNofCreators; i++)
- {
- LStr255 lCreator = sCreators[i];
- if (lPortCreator.BeginsWith(lCreator))
- {
- lAllowInList = true;
- break;
- }
- }
- }
-
- return lAllowInList;
- }
-